﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SaludOcupacional.Model;
using SaludOcupacional.Controller;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace SaludOcupacional
{
    /// <summary>
    /// Interaction logic for VistaReporte.xaml
    /// </summary>
    public partial class VistaReporte : Window
    {

        public VistaReporte(string queryString, ReportClass reporte)
        {
            InitializeComponent();
            this.MyCrystalReportViewer.BackColor = System.Drawing.Color.AliceBlue;
            string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=SaludOcupacional;Integrated Security=True";
            //string queryString = "SELECT cod_analisis, nombre, apellido_paterno, apellido_materno,  oido_izq, oido_der, bilateral FROM AnalisisAudiometrico a, Empleado e  WHERE AnalisisAudiometrico.ci_empleado = Empleado.ci";
            //queryString = "SELECT AnalisisAudiometrico.cod_analisis, Empleado.nombre, Empleado.apellido_paterno, Empleado.apellido_materno, AnalisisAudiometrico.oido_izq, AnalisisAudiometrico.oido_der, AnalisisAudiometrico.bilateral FROM AnalisisAudiometrico INNER JOIN Empleado ON AnalisisAudiometrico.ci_empleado = Empleado.ci";
            //SaludOcupacionalDataSet dataset = new SaludOcupacionalDataSet();
            DataSet ds = new DataSet("myset");

            //ReporteAudiometrico reporte = new ReporteAudiometrico();
            //ReporteAudiometricoDs ds = new ReporteAudiometricoDs();
            
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = new SqlCommand(queryString, connection);               
                adapter.Fill(ds);
                reporte.SetDataSource(ds.Tables[0]);               
            }
            
            this.MyCrystalReportViewer.ReportSource = reporte;





        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
